<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>宣传板新建</title>
    <script src="../../js/header.js"></script>
    <style type="text/css">
        html, body, #BoardInfo {
            padding: 0px;
            margin: 0px;
        }
        #BoardInfo{
            border-top: 3px solid #0D9AFF;
            padding: 25px;
        }
        .tab-title{
            font-size: 16px;
            font-weight: bold;
            border-left: 4px solid #0D9AFF;
            font-family: PingFangSC-Medium;
            padding-left:10px;
            margin-bottom: 20px;
        }
        .el-dialog__footer {
            padding: 10px 20px 20px;
            text-align: center;
            -webkit-box-sizing: border-box;
            box-sizing: border-box;
        }
        .el-dialog__body {
            color: rgb(96, 98, 102);
            font-size: 14px;
            word-break: break-all;
            padding: 0px 20px;
        }
        #excel {
            display: none;
        }
        .el-input__inner {
            -webkit-appearance: none;
            background-color: #FFF;
            background-image: none;
            border-radius: 4px;
            border: 1px solid #DCDFE6;
            -webkit-box-sizing: border-box;
            box-sizing: border-box;
            color: #606266;
            display: inline-block;
            font-size: inherit;
            height: 30px;
            line-height: 30px;
            outline: 0;
            padding: 0 15px;
            -webkit-transition: border-color .2s cubic-bezier(.645,.045,.355,1);
            transition: border-color .2s cubic-bezier(.645,.045,.355,1);
        }

        .el-select {
            width: 100%;
        }

        /* 搜索按钮样式修改 */
        #BoardInfo .el-button.is-circle.search_btn{
            position: absolute;
            right: 0;
            top: 0;
            border: 0;
            background: none;
        }
        #BoardInfo .el-button.is-circle.search_btn i{
            font-size: 17px;
        }

        .form_date_width .el-date-editor.el-input, .el-date-editor.el-input__inner {
            width : 100%;
        }
    </style>
</head>

<body>
<div v-cloak id="BoardInfo">
	<div style="margin-top: 10px;">
	    <el-form :model="Detail" :rules="rules" ref="Detail" label-width="140px" class="form_date_width">
	        <el-row>
	            <el-col :span="9">
	                <el-form-item label="创建人:"  prop="createUser" label-width="110px" :rules="rules.createUser">
	                    <el-input v-model="Detail.createUser"  placeholder=""  disabled></el-input>
	                </el-form-item>
	            </el-col>
	            <el-col :span="9">
	                <el-form-item label="创建单位:" prop="createUserunit" label-width="190px" :rules="rules.createUserunit">
	                    <el-input v-model="Detail.createUserunit"  placeholder=""  disabled></el-input>
	                </el-form-item>
	            </el-col>
	        </el-row>
	        <el-row>
	            <el-col :span="9">
	                <el-form-item label="创建时间:"  prop="createTime" label-width="110px" :rules="rules.createTime">
	                    <el-date-picker type="date"v-model="Detail.createTime" placeholder="" value-format="yyyy-MM-dd HH:mm" disabled></el-date-picker>
	                </el-form-item>
	            </el-col>
	        </el-row>
	        <el-row>
	            <el-col :span="22">
	                <el-form-item label="标题:"  prop="title" label-width="110px" :rules="rules.title">
	                    <el-input v-model.trim="Detail.title" placeholder="" maxlength="500" :disabled="formDisabled"></el-input>
	                </el-form-item>
	            </el-col>
	        </el-row>
	        <el-row>
	            <el-col :span="22">
	                <el-form-item label="内容:"  prop="draftContent" label-width="110px" :rules="rules.draftContent">
	                    <el-input
	                            type="textarea"
	                            :disabled="formDisabled"
	                            :autosize="{ minRows: 8, maxRows: 8}"
	                            placeholder=""
	                            maxlength="500"
	                            show-word-limit
	                            v-model="Detail.draftContent"
								maxlength="300" show-word-limit clearable
						>
	                    </el-input>
	                </el-form-item>
	            </el-col>
	        </el-row>
	        <el-row>
	            <el-col :span="22">
	                <el-form-item label="附件:" prop="" label-width="110px">
	                    <iframe width="100%"  style="height: 200px;border: none;"   :src="link"></iframe>
	                </el-form-item>
	            </el-col>
	        </el-row>
	
	        <el-row>
	            <el-col :span="22">
	                <div style="float:right;">
	                    <el-button type="primary" size="small" style="width: 60px;height: 30px;" @click="save('Detail')">暂存</el-button>
	                    <el-button type="success" size="small" style="width: 60px;height: 30px;" @click="fabu('Detail')">发布</el-button>
	                </div>
	            </el-col>
	        </el-row>
	    </el-form>
	</div>
</div>
<script>

    var vm = new Vue({
        el: '#BoardInfo',
        data() {
            return {
                uuid:'',
                link:'',
                Detail: {
                    Id : '',
                    title:'',
                    createUserunit : '',
                    createUser : '',
                    createTime:'',
                    draftContent : ''
                },
                rules: {
                    title: [{
                        required : true,
                        message : '必填',
                        trigger : 'blur'
                    },{
                        max : 500,
                        message : '长度最大为500个字符',
                        trigger : 'blur'
                    }],
                    createUserunit: [{
                        required : true,
                        message : '必填',
                        trigger : 'blur'
                    }],
                    createUser: [{
                        required : true,
                        message : '必填',
                        trigger : 'blur'
                    }],
                    createTime: [{
                        required : true,
                        message : '必填',
                        trigger : 'blur'
                    }],
                    draftContent:[{
                        required : true,
                        message : '必填',
                        trigger : 'blur'
                    },{
                        max : 5000,
                        message : '长度最大为5000个字符',
                        trigger : 'blur'
                    }]
                },
                formDisabled: false
            }
        },
        mounted(){
            this.getUuid();
            this.created();
        },
        methods: {
            //获取当前登录人信息
            created(){
                var  userInfo = JSON.parse(localStorage.getItem("userInfo"));
                this.Detail.createUser= userInfo.loginName;
                this.Detail.createUserunit  = userInfo.orgName;
                let date = new Date();
                let y = date.getFullYear();
                let MM = date.getMonth() + 1;
                MM = MM < 10 ? ('0' + MM) : MM;
                let d = date.getDate();
                d = d < 10 ? ('0' + d) : d;
                let h = date.getHours();
                h = h < 10 ? ('0' + h) : h;
                let m = date.getMinutes();
                m = m < 10 ? ('0' + m) : m;
                let s = date.getSeconds();
                s = s < 10 ? ('0' + s) : s;
               	this.Detail.createTime = y + '-' + MM + '-' + d;
            },
            // 表单暂存提交
            save(Detail) {
                this.Detail.id= this.uuid;
                this.$refs.Detail.validate((valid) => {
                	this.Detail.id= this.uuid;
                    if (valid) {
                        axios({
                            method: 'post',
                            url: '/dzjwgr/board/save',
                            data: this.Detail
                        })
                            .then((response) => {
                            let data = response.data;
                        if (data.code == 200) {
                            this.$message({
                                type: 'success',
                                message: '暂存成功!'
                            });
                            this.clearAll();
                        } else {
                            this.$message.error(data.msg);
                        }
                    });
                    }
                })

            },
            fabu(Detail) {
                this.$refs.Detail.validate((valid) => {
                    this.Detail.id= this.uuid;
                    if (valid) {
                        axios({
                            method: 'post',
                            url: '/dzjwgr/board/saverelease',
                            data: this.Detail
                        })
                            .then((response) => {
                            let data = response.data;
                        if (data.code == 200) {
                            this.$message({
                                type: 'success',
                                message: '发布成功!'
                            });
                            this.clearAll();
                        } else {
                            this.$message.error(data.msg);
                        }
                    });
                    }
                })
            },
            //获取UUID的方法
            getUuid() {
                axios({
                    method: 'get',
                    url: '/dzjwgr/uuid/getUuid',
                })
                    .then(response => {
                    if (response.data.code == 200) {
                    this.uuid = response.data.data;
                    this.link="../upload/annex.html?uuid="+this.uuid+"&flag=1";
                } else {
                    this.$message.error(response.data.msg);
                }
            })
            .catch(function (error) {
                    console.log(error);
                });
            },
            clearDetail(){
                this.Detail.Id = '',
                this.Detail.title='',
                this.Detail.draftContent =''
            },
            clearAll(){
                this.getUuid();
                this.created();
                this.clearDetail();
            },
            // 设置允许填写和不允许填写
            checkDisabled(n){
                if(n){
                    this.formDisabled = true;
                }else{
                    this.formDisabled = false;
                }
            },


        }
    })
</script>
</body>
</html>